package com.woniuxy.education.mapper;


import com.woniuxy.education.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {
    //通过c_id查出所有的作业列表
    @Select("<script>select * from homework where c_id = #{c_id}" +
            "<if test=\"job_type!=null and job_type!=''\">"+
            "and job_type=#{job_type}"+
            "</if>"+
            "<if test=\"subject!=null and subject!=''\">"+
            "and subject=#{subject}"+
            "</if>"+
            "<if test=\"status!=null and status!=''\">"+
            "and status=#{status}"+
            "</if>"+
    "</script>")
    public List<Homework> findHomework(SelectWork selectWork);

    //通过c_id查出所有的考试列表
    @Select("select * from  test_table where c_id = #{c_id}")
    public List<TestPage> findtestPage(int c_id);

    //通过作业的id查询出当前作业全部题目
    @Select("select id,choose,completion,answer_questions,composition from homework_titleid where h_id=#{id}")
    public Titleids findhomework_titleid(int id);

    //通过考试的id查询出当前试卷全部题目
    @Select("select id,choose,completion,answer_questions,composition from test_titleid where t_id=#{id}")
    public Titleids findtest_titleid(int id);
    /**
     *
     * @param
     * @return
     */
    //查选择题
    @Select("select * from choose_table where id=#{qid}")
    public Choose_table findChoose(int qid);
    //查填空题
    @Select("select * from Completion_table where id=#{qid}")
    public Completion_table findCompletion(int qid);
    //查解答题
    @Select("select * from answer_questions_table where id=#{qid}")
    public Answer_Questions_table findAnswer_Questions(int qid);
    //查作文题
    @Select("select * from composition_table where id=#{qid}")
    public Composition_table findComposition(int qid);

    /**
     * 将写完的作业添加到数据库
     */
    @Insert("insert into completed_work values " +
            "(default,#{choose_answer},#{completion_answer}," +
            "#{answer_questions_answer},#{composition_answer},#{h_id},#{u_id},#{state})")
    public boolean insertCompleted_work(Completed_work completed_work);

    /**
     * 将写完的试卷答案添加到数据库
     */
    @Insert("insert into completed_test values " +
            "(default,#{choose_answer},#{completion_answer}," +
            "#{answer_questions_answer},#{composition_answer},#{t_id},#{u_id})")
    public boolean insertCompleted_test(Completed_test completed_test);

    /**
     * 完成提交后修改状态
     */
    //修改作业状态
    @Update("update homework set status = '已完成' where id = #{homeortestid}")
    public boolean updateHomeworkstatus(int homeortestid);
    //修改考试状态
    @Update("update test_table set status = '已完成' where id = #{homeortestid}")
    public boolean updateTeststatus(int homeortestid);
    //查询题库已做的题目
    @Select("select * from topics_table where u_id=#{userid}")
    public Topics_table SelectTopics_table(int userid);
    //将做了的选择题插入已做题库
    @Update("update topics_table set choose_isdo=#{ChooseString} where u_id=#{u_id}")
    public boolean UpdateChooseIsdo(@Param("ChooseString") String  ChooseString,@Param("u_id")int u_id);
    //将做了的填空题插入已做题库
    @Update("update topics_table set completion_isdo=#{completion_isdo} where u_id=#{u_id}")
    public boolean UpdateCompletionIsdo(@Param("completion_isdo") String  completion_isdo,@Param("u_id")int u_id);
    //将做了的解答题插入已做题库
    @Update("update topics_table set answer_questions_isdo=#{answer_questions_isdo} where u_id=#{u_id}")
    public boolean UpdateAnswerQuestionsIsdo(@Param("answer_questions_isdo") String  ChooseString,@Param("u_id")int u_id);
    //将做了的作文题插入已做题库
    @Update("update topics_table set composition_isdo=#{composition_isdo} where u_id=#{u_id}")
    public boolean UpdateCompositionIsdo(@Param("composition_isdo") String  ChooseString,@Param("u_id")int u_id);
    //将做了的但是错的选择题插入已做题库
    @Update("update topics_table set choose_iserror=#{ChooseErrorString} where u_id=#{u_id}")
    public boolean UpdateChooseIsError(@Param("ChooseErrorString") String  ChooseErrorString,@Param("u_id")int u_id);
    //将做了的但是错的填空题插入题库
    @Update("update topics_table set completion_iserror=#{completion_isErrorString} where u_id=#{u_id}")
    public boolean UpdateCompletionIsError(@Param("completion_isErrorString") String  completion_isErrorString,@Param("u_id")int u_id);
    //将做了的但是错的解答题插入题库
    @Update("update topics_table set answer_questions_iserror=#{answer_questions_isErrorString} where u_id=#{u_id}")
    public boolean UpdateAnswerQuestionsIsError(@Param("answer_questions_isErrorString") String  answer_questions_isErrorString,@Param("u_id")int u_id);
    //将做了的但是错的作文题插入题库
    @Update("update topics_table set composition_iserror=#{composition_isErrorString} where u_id=#{u_id}")
    public boolean UpdateCompositionIsError(@Param("composition_isErrorString") String  composition_isErrorString,@Param("u_id")int u_id);

    /**
     * 学生提问后插入进question_ask
     */
    @Insert("insert into question_ask values " +
            "(default,#{type},#{subject},#{tea_name}," +
            "#{context},#{upload_time},#{answer},#{recovery_tea},#{recovery_time},#{state},#{u_id} )")
    public boolean insertquestion(Question_ask question_ask);
    //查找学生提的所有问题
    @Select("select * from question_ask")
    public List<Question_ask> findAllQuestion();
    //查找指定班级所有学生
    @Select("select * from student where c_id=#{c_id}")
    public List<Student> findStudentsByC_id(Integer c_id);
    //查找指定班级未注册账号的所有学生
    @Select("select * from student where c_id=#{c_id} and u_id=null")
    public List<Student> findStudentsByC_idAndU_id();

    //查找学生所有考试的成绩
    @Select("select * from test_score where u_id = #{u_id} order by test_time")
    public List<Test_score> findTestScore(int u_id);
    //查询班级考试的平均成绩
    @Select("select * from class_adv where level = #{level} and c_id=#{c_id} order by test_time")
    public List<Class_adv> findClass_adv(@Param("level") int level,@Param("c_id") int c_id);
    //查询年级考试的平均成绩
    @Select("select * from grade_adv where level = #{level} order by test_time")
    public List<Grade_adv> findGrade_adv(int level);

    /**
     * 查找学生收藏的题目
     */
    //
    //选择题
    @Select("select choose from collectiontitles where u_id=#{u_id}")
    public String findCollectChoose(int u_id);
    //填空题
    @Select("select completion from collectiontitles where u_id=#{u_id}")
    public String findCollectCompletion(int u_id);
    //解答题
    @Select("select answer_questions from collectiontitles where u_id=#{u_id}")
    public String findCollectAnswer_Questions(int u_id);
    //作文题
    @Select("select composition from collectiontitles where u_id=#{u_id}")
    public String findCollectComposition(int u_id);

    /**
     * 添加收藏题目
     */
    //选择题
    @Update("update collectiontitles set choose=#{choose} where u_id=#{u_id}")
    public boolean UpdateCollectChoose(@Param("choose") String choose,@Param("u_id") int u_id);
    //填空题
    @Update("update collectiontitles set completion=#{completion} where u_id=#{u_id}")
    public boolean UpdateCollectCompletion(@Param("completion") String completion,@Param("u_id") int u_id);
    //解答题
    @Update("update collectiontitles set answer_questions=#{answer_questions} where u_id=#{u_id}")
    public boolean UpdateCollectAnswer_Questions(@Param("answer_questions") String answer_questions,@Param("u_id") int u_id);
    //作文题
    @Update("update collectiontitles set composition=#{composition} where u_id=#{u_id}")
    public boolean UpdateCollectComposition(@Param("composition") String composition,@Param("u_id") int u_id);

    /**
     * 查全部收藏的题目id
     */
    @Select("select * from collectiontitles where u_id=#{u_id}")
    Collectiontitles findCollectTitle(int u_id);

    /**
     * 刷题
     */
    //刷全部的选择题
    @Select("select * from choose_table where subject=#{subject} and grade=#{grade}")
    List<Choose_table> findGradeToChoose(@Param("subject") String subject,@Param("grade") String grade);
    //查询已经做过的选择题
    @Select("select choose_isdo from topics_table where u_id=#{u_id}")
    String findIsdoChoose(int u_id);
    //查询已经做过的错的选择题
    @Select("select choose_iserror from topics_table where u_id=#{u_id}")
    String findIsErrorChoose(int u_id);
    //根据年级和科目查询所有的选择题id
    @Select("select id from choose_table where subject=#{subject} and grade=#{grade}")
    List<Integer> findChooseIds(@Param("subject") String subject,@Param("grade") String grade);


}
